package com.imyours.webservice.services;

import java.util.HashMap;
import java.util.Map;

import com.imyours.users.session.UserSessionManager;
import com.imyours.webservice.service.Context;
import com.imyours.webservice.service.ContextService;
import com.imyours.webservice.services.annotation.Service;
/**
 * @author SLevenc
 *
 */
@Service(name="login")
public class Login extends ContextService {

	public Login(Context context) {
		super(context);
	}
	/**
	 * 登陆接口  传入  username password  登陆成功返回sessionIds
	 */
	public void execute() {
		String username = context.getParameter().get("username");
		String password = context.getParameter().get("password");

		if (username != null && password != null) {
			String sessionId = UserSessionManager.getInstance().login(username, password);
			if(sessionId!=null){
				Map<String,Object> resultMap  = new HashMap<String, Object>();
				resultMap.put("sessionId", sessionId);
				context.setResult(resultMap);
				context.success();
			}else{
				context.fail(1, "username or password is mismatch");
			}
		}else{
			context.fail(0, "username or password is null");
		}

	}

}
